package com.cl.ks.config;

import com.jandar.pile.common.config.JwtConfig;
import com.jandar.pile.common.util.JwtUtil;
import com.cl.pile.rule.process.RuleMatcher;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

/**
 * @author chenyitao
 * @date 2021/4/19
 */
@Configuration
public class AppConfig {
    private final RuleMatcher ruleMatcher;
    private final ValueConfig config;

    public AppConfig(ValueConfig config) {
        this.config = config;
        this.ruleMatcher = new RuleMatcher();
    }
    @Bean
    public RuleMatcher getRuleMatcher() {
        return ruleMatcher;
    }
    @Bean
    @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
    public JwtUtil<Long, Long> jwtUtil() {
        JwtConfig jwtConfig = JwtConfig.builder()
                .issuer(config.getJwtIssuer())
                .expiration(String.valueOf(config.getJwtExpiration()))
                .security(config.getJwtSecurity())
                .tokenUnique(String.valueOf(config.getJwtTokenUnique()))
                .build();
        return new JwtUtil<>(jwtConfig);
    }

}
